﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.InfoCardClaim
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.IO;
using System.Text;

namespace Microsoft.InfoCards
{
  internal class InfoCardClaim
  {
    private string m_id;
    private string m_claimValue;
    private string m_displayTag;
    private string m_description;

    public InfoCardClaim()
    {
    }

    public InfoCardClaim(string id, string value)
      : this(id, value, (string) null, (string) null)
    {
    }

    public InfoCardClaim(string id, string value, string description, string displaytag)
    {
      if (string.IsNullOrEmpty(id))
        throw InfoCardTrace.ThrowHelperArgumentNull(nameof (id));
      this.m_id = id;
      this.m_claimValue = value;
      this.m_displayTag = displaytag;
      this.m_description = description;
    }

    public string Id
    {
      get
      {
        return this.m_id;
      }
    }

    public string Value
    {
      get
      {
        return this.m_claimValue;
      }
      set
      {
        this.m_claimValue = value;
      }
    }

    public string DisplayTag
    {
      get
      {
        return this.m_displayTag;
      }
    }

    public string Description
    {
      get
      {
        return this.m_description;
      }
    }

    public override string ToString()
    {
      return this.m_claimValue;
    }

    public void ThrowIfNotComplete()
    {
      if (string.IsNullOrEmpty(this.m_id))
        throw InfoCardTrace.ThrowHelperError((Exception) new SerializationIncompleteException(this.GetType()));
    }

    public void Serialize(BinaryWriter writer)
    {
      this.ThrowIfNotComplete();
      if (writer == null)
        throw InfoCardTrace.ThrowHelperArgumentNull(nameof (writer));
      Utility.SerializeString(writer, this.m_id);
      Utility.SerializeString(writer, this.m_displayTag);
      Utility.SerializeString(writer, this.m_description);
      Utility.SerializeString(writer, this.m_claimValue);
    }

    public void DeSerialize(BinaryReader reader)
    {
      this.m_id = Utility.DeserializeString(reader);
      this.m_displayTag = Utility.DeserializeString(reader);
      this.m_description = Utility.DeserializeString(reader);
      this.m_claimValue = Utility.DeserializeString(reader);
    }

    public void Encrypt(PinProtectionHelper pinHelper)
    {
      byte[] bytes = new UnicodeEncoding().GetBytes(this.m_claimValue);
      this.m_claimValue = Convert.ToBase64String(pinHelper.Encrypt(bytes));
    }

    public void Decrypt(PinProtectionHelper pinHelper)
    {
      UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
      byte[] encrypted = Convert.FromBase64String(this.m_claimValue);
      this.m_claimValue = unicodeEncoding.GetString(pinHelper.Decrypt(encrypted));
    }

    public InfoCardClaim Clone()
    {
      return new InfoCardClaim((string) this.m_id.Clone(), string.IsNullOrEmpty(this.m_claimValue) ? (string) null : (string) this.m_claimValue.Clone(), string.IsNullOrEmpty(this.m_description) ? (string) null : (string) this.m_description.Clone(), string.IsNullOrEmpty(this.m_displayTag) ? (string) null : (string) this.m_displayTag.Clone());
    }
  }
}
